home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / OOPTUT34.ZIP / WRONGOOP.PAS < prev   
Pascal/Delphi Source File  |  1993-05-31  |  2KB  |  103 lines

  1. program wrong_oop;
  2.  
  3. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  4. { Program to illustrate the need for Virtual Methods in             }
  5. { object-oriented programming. Compare with RIGHTOOP.PAS            }
  6. {                                                                   }
  7. { WRONGOOP.PAS  ->  WRONGOOP.EXE    R. Shaw  26.4.91    31.5.93     }
  8. {___________________________________________________________________}
  9.  
  10. uses Crt;
  11.  
  12. type
  13.  
  14. staff = object
  15.       Name : string;
  16.       constructor Init(SurName : string );
  17.       procedure script1;           {                                  }
  18.       procedure script2;           { These are all static procedures  }
  19.       procedure action1;           { and can be inherited as they are.}
  20.       procedure action2;           {                                  }
  21.       end;
  22.  
  23. junior = object( staff )
  24.            procedure script1;       {As static procedures, they will not }
  25.            procedure script2;       {override those inherited from staff }
  26.          end;
  27.  
  28. var
  29.    LetterName : string;
  30.  
  31. constructor staff.Init( SurName : string );
  32. begin
  33.      Name := SurName;
  34. end;
  35.  
  36. procedure staff.script1;
  37. begin
  38.      writeln( Name,
  39.          ': Please send the duplicated letters to all our customers.');
  40.      writeln( '        If you have a problem, please ask me.');
  41. end;
  42.  
  43. procedure staff.script2;
  44. begin
  45.      LetterName := 'OD';
  46.      writeln(Name,': The letter is headed ',LetterName,'.');
  47.      writeln;
  48. end;
  49.  
  50. procedure staff.action1;
  51. begin
  52.      script1;
  53. end;
  54.  
  55. procedure staff.action2;
  56. begin
  57.      script2;
  58. end;
  59.  
  60.  
  61. procedure junior.script1;
  62. begin
  63.      writeln;
  64.      writeln( '< later >');
  65.      writeln;
  66.      writeln( Name, ': I do not know the letter to send for an overdraft' );
  67.      writeln;
  68. end;
  69.  
  70. procedure junior.script2;
  71. begin
  72.      writeln( Name, ': Thank you. ');
  73.      writeln;
  74.      writeln( '< later still >' );
  75.      writeln;
  76.      writeln( Name, ': As you requested, I sent the letter headed ',LetterName,'.');
  77. end;
  78.  
  79. {Main}
  80.  
  81. var
  82.    Young      : junior;
  83.    Old        : staff;
  84.  
  85. begin
  86.      clrscr;
  87.  
  88.      Young.Init( 'NEWMAN' );
  89.      Old.Init( 'SENIOR' );
  90.  
  91.      Old.action1;
  92.      Young.action1;
  93.      Old.action2;
  94.      Young.action2;
  95.  
  96.      gotoXY(10,24);
  97.      write('Press any key to conclude: ');
  98.      repeat until keypressed;
  99.      clrscr;
  100. end.
  101.  
  102. { end of listing }
  103.